package com.lagou.handler;

import com.lagou.zk.MyZkClient;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author wuyuhan
 * @date 2021/1/12 22:41
 */
public class MyIdleStateHandler extends ChannelInboundHandlerAdapter implements ApplicationContextAware {

    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context=applicationContext;
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        System.out.println("5秒未响应，更新节点");
        MyZkClient myZkClient = (MyZkClient)context.getBean("MyZkClient");
        myZkClient.updateTime(0);
    }

}
